package com.wqiuqiu.gulimall.product.service.impl;

import com.wqiuqiu.gulimall.product.vo.AttrNoId;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wqiuqiu.common.PageUtils;
import com.wqiuqiu.common.Query;

import com.wqiuqiu.gulimall.product.dao.SkuSaleAttrValueDao;
import com.wqiuqiu.gulimall.product.entity.SkuSaleAttrValueEntity;
import com.wqiuqiu.gulimall.product.service.SkuSaleAttrValueService;


@Service("skuSaleAttrValueService")
public class SkuSaleAttrValueServiceImpl extends ServiceImpl<SkuSaleAttrValueDao, SkuSaleAttrValueEntity> implements SkuSaleAttrValueService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuSaleAttrValueEntity> page = this.page(
                new Query<SkuSaleAttrValueEntity>().getPage(params),
                new QueryWrapper<SkuSaleAttrValueEntity>()
        );

        return new PageUtils(page);
    }


    /**
     * 根据skuIds得到全部SkuSaleAttrValueEntity
     * @param skuIds
     * @return
     */
    @Override
    public List<SkuSaleAttrValueEntity> listBySkuIds(List<Long> skuIds) {
//        return this.list(new QueryWrapper<SkuSaleAttrValueEntity>().in("sku_id",skuIds));
        return this.baseMapper.listBySkuIds(skuIds);
    }

    /**
     * 按attr_name分组，然后对attr_value聚合，去重
     * SELECT attr_name, GROUP_CONCAT(DISTINCT attr_value SEPARATOR ',') AS attr_values
     * FROM `pms_sku_sale_attr_value` WHERE sku_id IN (9, 10)
     * GROUP BY attr_name
     * @param skuIds
     * @return
     */
    @Override
    public List<AttrNoId> getAttrNameAndAttrValueBySkuIds(List<Long> skuIds) {
        return this.baseMapper.getAttrNameAndAttrValueBySkuIds(skuIds);
    }

    /**
     * 根据skuId 得到attr_name attr_value
     * SELECT CONCAT(attr_name,"：",attr_value) FROM `pms_sku_sale_attr_value` WHERE sku_id= 1
     * @param skuId
     * @return
     */
    @Override
    public List<String> getSkuSaleAttrValuesAsStringList(Long skuId) {
        return baseMapper.getSkuSaleAttrValuesAsStringList(skuId);

    }


}